package linshuai;

import javafx.geometry.Side;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;

public class Timeseries extends LineChart<Number, Number> {
	public Timeseries(int ymax) {
		super(createAxis(0), createAxis(ymax));
		setMinSize(0, 0);
		setLegendSide(Side.RIGHT);
		setLegendVisible(true);
		setCreateSymbols(false);
		setAnimated(false);
	}

	public void setup(String ... legend) {
		getData().clear();
		for(String l: legend) {
			Series<Number,Number> s = new Series<Number,Number>();
			s.setName(l);
			getData().add(s);
		}
	}

	public void add(int tick, Number ... count) {
		int i = 0;
		for(Series<Number, Number> series: getData())
			series.getData().add(new XYChart.Data<Number,Number>(
				tick, count[i++]));
	}

	private static NumberAxis createAxis(int max) {
		NumberAxis axis = new NumberAxis();
		if(max > 0) {
			axis.setUpperBound(max);
			axis.setAutoRanging(false);
		}
		axis.setMinorTickVisible(false);
		axis.setTickMarkVisible(false);
		axis.setAnimated(false);
		return axis;
	}
}
